#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <list>
#include <climits>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
using namespace std;
const int MAXN = 10000+1;
struct CQSet {
	int father[MAXN];
	void reset(int n) {
		for(int i = 0; i < n; ++i)
			father[i] = i;
	}

	bool inSameSet(int a, int b) {
		int ancA = getAncestor(a);
		int ancB = getAncestor(b);
		return ancA == ancB;
	}
	int getAncestor(int x) {
		if(x == father[x]) return x;
		return father[x] = getAncestor(father[x]);
	}
	int combine(int a, int b) {
		int ancA = getAncestor(a);
		int ancB = getAncestor(b);
		return father[ancB] = ancA;
	}
};
struct CEdge{
	int a, b;
	CEdge(int _a, int _b):a(_a), b(_b){}
};
struct CMyList : list<CEdge>{};
struct CProblem {
	CMyList li;
	char buf[10];
	CQSet s;
	void printAns(int n){
		int ans[2];
		li.clear();
		ans[0] = ans[1] = 0;
		while(scanf("%1s", buf), buf[0]!='e') {
			char ch = buf[0];
			if(ch == 'q') {
				int a, b;
				scanf("%d%d", &a, &b);
				s.reset(n+1);
				int type = 0;
				for(CMyList::iterator it = li.begin(); it!=li.end(); ++it) {
					s.combine(it->a, it->b);
					if(s.inSameSet(a, b)) {
						type = 1;
						break;
					}
				}
				ans[type]++;
			} else if(ch == 'c') {
				int a, b;
				scanf("%d%d", &a, &b);
				li.push_back(CEdge(a, b));
			} else if(ch == 'd') {
				int a, b;
				scanf("%d", &a);
				for(CMyList::iterator it = li.begin(); it!=li.end();) {
					if(it->a == a || it->b == a) {
						it = li.erase(it);
					} else {
						it++;
					}
				}
			}
		}
		printf("%d , %d\n", ans[1], ans[0]);
	}
};
int main() {
#ifdef DEBUG
    freopen("in.txt", "rt", stdin);
#endif
    static CProblem cp;
    int n;
    while(scanf("%d", &n) != EOF) {
        cp.printAns(n);
    }
    return 0;
}
